package com.oa.service.impl;

import com.oa.pojo.Evection;
import com.oa.pojo.User;
import com.oa.service.EvectionService;
import com.oa.mapper.EvectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author zhou
* @description 针对表【evection】的数据库操作Service实现
* @createDate 2023-11-03 14:00:39
*/
@Service
public class EvectionServiceImpl implements EvectionService {
    @Autowired
    private EvectionMapper evectionMapper;

    @Override
    public List<Evection> selectAllByIdEvcation(Evection evection){
        List<Evection> evectionList = new ArrayList<>();
        evectionList = evectionMapper.selectAllByIdEvcation(evection);
        return evectionList;
    }
    @Override
    public int deleteEvection(Integer id) {
        Evection evection = new Evection();
       evection.setId(id);
        return evectionMapper.deleteEvection(evection);
    }

    @Override
    public int updateEvection(Evection evection) {
        int flag = 0;
        //拿到所有假期信息
       Evection evection1=new Evection();
        List<Evection> evectionList = evectionMapper.selectAllByIdEvcation(evection1);
        flag= evectionMapper.updateEvection(evection);
        return flag;
    }

    @Override
    public int insertEvection(Evection evection) {
        int flag = 0;
        Evection evection1 = new Evection();
        List<Evection> evectionList = evectionMapper.selectAllByIdEvcation(evection);
        //在全部用户中遍历，避免用户名,份证，电话号码重复
        for (Evection e : evectionList) {
            if ( e.getId().equals(evection.getId())){
                flag = -1;
                return flag;
            }
        }
        System.out.println(evection);
        flag= evectionMapper.insertEvection(evection);
        return flag;
    }
}





